package com.reservationserver.service.impl.admin;

import com.reservationpojo.domin.vo.InsertReplyvo;

import com.reservationpojo.domin.vo.Usercommentvo;
import com.reservationpojo.entity.Comment;
import com.reservationserver.mapper.admin.Commentmapper;
import com.reservationserver.service.admin.Commentservice;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import static java.time.LocalDateTime.now;
import static java.time.chrono.ChronoLocalDateTime.timeLineOrder;

@Slf4j
@Service
@RequiredArgsConstructor
public class CommentserviceImpl implements Commentservice {
private  final Commentmapper commentmapper;

    @Override
    public List<Comment> getComment() {



        return commentmapper.getComment();
    }

    @Override
    public void insertReply(InsertReplyvo insertReplyvo) {
        commentmapper.insertReply(insertReplyvo);
    }

    @Override
    public void insretcomment(Usercommentvo usercommentvo) {
        Comment comment=new Comment();
        LocalDateTime data=now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter idformatter=DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSSSSSS");
        String commentid=data.format(idformatter);
        commentid=commentid+"Comment";
        String formattedDateTime = data.format(formatter);
        LocalDateTime dateTime = LocalDateTime.parse(formattedDateTime, formatter);
        log.info("dateTime:{}",dateTime);
        comment.setCommentId(commentid);
        comment.setCommentData(dateTime);
        comment.setCommentText(usercommentvo.getCommentText());
        comment.setStudentId(usercommentvo.getStudentId());
        log.info("comment:{}",comment);
        commentmapper.insretcomment(comment);
    }

    @Override
    public List<Comment> getUserComment(String userId) {
        List<Comment> comments=commentmapper.getUserComment(userId);
        log.info("comments:{}",comments);
        return comments;
    }

    @Override
    public void deletecomment(String commentId) {
        commentmapper.deleteComment(commentId);
    }

}
